package top.chengdongqing.mishop.product

import org.springframework.web.bind.annotation.*
import top.chengdongqing.mishop.common.pageable.Page1
import top.chengdongqing.mishop.common.pageable.PageRequest1
import top.chengdongqing.mishop.product.dto.ProductSearchDTO
import top.chengdongqing.mishop.product.vo.ProductDetailsVO
import top.chengdongqing.mishop.product.vo.ProductParentVO
import top.chengdongqing.mishop.product.vo.ProductVO
import top.chengdongqing.mishop.product.vo.RecommendedProductVO

@RestController
@RequestMapping("/products")
class ProductController(private val productService: ProductService) {

    @GetMapping("/categories")
    fun findCategories(
        @RequestParam(defaultValue = "10") limits: Int,
        @RequestParam(defaultValue = "0") itemsLimits: Int,
        @RequestParam(defaultValue = "false") withBanners: Boolean
    ): List<ProductParentVO> {
        return productService.findCategories(limits, itemsLimits, withBanners)
    }

    @GetMapping("/brands")
    fun findBrands(
        @RequestParam(defaultValue = "10") limits: Int,
        @RequestParam(defaultValue = "0") itemsLimits: Int
    ): List<ProductParentVO> {
        return productService.findBrands(limits, itemsLimits)
    }

    @GetMapping("/names/hot")
    fun findNamesHot(@RequestParam(defaultValue = "10") limits: Int): List<String> {
        return productService.findNamesHot(limits)
    }

    @GetMapping("/names/like")
    fun findNamesLike(@RequestParam keyword: String): List<String> {
        return productService.findNamesLike(keyword)
    }

    @GetMapping("/search")
    fun searchProducts(searchDTO: ProductSearchDTO, pageRequest: PageRequest1): Page1<ProductVO> {
        return productService.searchProducts(searchDTO, pageRequest.get())
    }

    @GetMapping("/recommended")
    fun findRecommended(@RequestParam(defaultValue = "10") limits: Int): List<RecommendedProductVO> {
        return productService.findRecommended(limits)
    }

    @GetMapping("/{id}")
    fun findDetails(@PathVariable id: Int): ProductDetailsVO {
        return productService.findDetails(id)
    }
}